package com.erp.staobaotrasg.utils;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.erp.staobaotrasg.R;


/**
 * Created by cfg on 2016/1/29.
 * function: 界面标题栏的控制
 */
public class TitleBarUtil {

    private static TextView txt_title; //标题栏的中心的文字
    private static RelativeLayout rl_back; //返回到按钮
    private static TextView txt_right;
    private static ImageView img_right;

    static RelativeLayout relativeLayout;

    private TitleBarUtil() {
    }

    /**
     * 只有一个标题的控件
     *
     * @param context
     * @param title
     */
    public static void setCommenTitleBar(Activity context, String title) {
        relativeLayout = (RelativeLayout) context.findViewById(R.id.RL_titlebar_background);
        relativeLayout.setBackgroundResource(R.color.product_color);
        if (title != null) { //判断设置的标题文字是否为空
            txt_title = (TextView) context.findViewById(R.id.TV_titlebar_title);
            txt_title.setText(title);
        }
    }

    /**
     * 含有返回按钮  右侧没有功能的界面控制
     *
     * @param context
     * @param title
     * @param hasBack
     */
    public static void setCommenTitleBar(final Activity context, String title, Boolean hasBack) {
        setCommenTitleBar(context, title);
        if (hasBack) { //设置为 true 的时候 让其显示
            rl_back = (RelativeLayout) context.findViewById(R.id.RL_titlebar_back);
            rl_back.setVisibility(View.VISIBLE);//设置为显示
            rl_back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.finish(); //点击按钮的事件
                }
            });
        }
    }

}
